package com.scu.hotelsystem.service;

import com.scu.hotelsystem.dao.ManagerDao;
import com.scu.hotelsystem.pojo.Manager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class ManagerServiceImpl implements ManagerService {
    @Autowired
    private ManagerDao managerDao;

    @Override
    public int verifyLogin(String account, String password) {
        int id;
        Manager manager;

        if (account.length() == 11){
            manager = managerDao.selectValidManagerByPhonePass(account, password);
        }else{
            try{ id = Integer.parseInt(account); }
            catch (NumberFormatException e){return FAILED;}
            manager = managerDao.selectValidManagerByIdPass(id, password);
        }

        return manager == null? FAILED : manager.getId();
    }
}
